﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace CPPEI.Coolzon.UI.Views
{
    public partial class RenderView
    {
        private bool _isShowScrollBar = false;

        /// <summary>
        /// 是否显示滚动条
        /// </summary>
        public bool IsShowScrollBar
        {
            get
            {
                return _isShowScrollBar;
            }
            set
            {
                _isShowScrollBar = value;
            }
        }

        private void OnUpdateScrollBar(Size currentSize)
        {
            if (_isShowScrollBar)
            {
                Size sceneSize = this._ctlMainFrame.GetSceneSize();
                if (sceneSize.Width > currentSize.Width)
                {
                    _ctlScrollBarHorizontal.Visibility = System.Windows.Visibility.Visible;
                    _ctlScrollBarHorizontal.Maximum = sceneSize.Width - currentSize.Width;
                    _ctlScrollBarHorizontal.ViewportSize = currentSize.Width;
                    _ctlScrollBarHorizontal.Value = 0;
                }
                else
                {
                    _ctlScrollBarHorizontal.Visibility = System.Windows.Visibility.Hidden;
                }

                if (sceneSize.Height > currentSize.Height)
                {
                    _ctlScrollBarVertical.Visibility = System.Windows.Visibility.Visible;
                    _ctlScrollBarVertical.Maximum = sceneSize.Height - currentSize.Height;
                    _ctlScrollBarVertical.ViewportSize = currentSize.Height;
                    _ctlScrollBarVertical.Value = 0;
                }
                else
                {
                    _ctlScrollBarVertical.Visibility = System.Windows.Visibility.Hidden;
                }
            }
        }

        private void _ctlScrollBarHorizontal_ValueChanged_1(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            double left = e.NewValue;
            Point cameraPos = this._ctlMainFrame.GetCameraPos();
            this._ctlMainFrame.MoveCameraToPos(left, cameraPos.Y);
        }

        private void _ctlScrollBarVertical_ValueChanged_1(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            double top = e.NewValue;
            Point cameraPos = this._ctlMainFrame.GetCameraPos();
            this._ctlMainFrame.MoveCameraToPos(cameraPos.X, top);
        }
    }
}
